//
//  HomeFlowBannerCell.m
//  BaseProject
//
//  Created by 王洋 on 2020/7/13.
//  Copyright © 2020 王洋. All rights reserved.
//

#import "HomeFlowBannerCell.h"

@interface HomeFlowBannerCell ()<SDCycleScrollViewDelegate>

@end

@implementation HomeFlowBannerCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.backgroundColor = [UIColor whiteColor];
        [self layout];
    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self.bannerView pp_clipCorners:UIRectCornerAllCorners radius:10];
    });
}

- (void)layout {
    
    [self addSubview:self.bannerView];
    
    [self.bannerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.mas_equalTo(10);
        make.right.bottom.mas_equalTo(-10);
    }];
}

- (void)configBannerCellWithImageArray:(NSMutableArray *)arr {
    
    self.bannerView.imageURLStringsGroup = arr;
}

- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index
{
    if (self.bigBanner) {
        [[StatisticManager shareManager]insertBrowseUserActiveQuantityWithType:@"2"];
    } else {
        [[StatisticManager shareManager]insertBrowseUserActiveQuantityWithType:@"4"];
    }
    if (self.CycleImgClickedBlock) {
        self.CycleImgClickedBlock(index);
    }
}

- (SDCycleScrollView *)bannerView {
    if (!_bannerView) {
        _bannerView = [[SDCycleScrollView alloc] init];
        _bannerView.bannerImageViewContentMode = UIViewContentModeScaleAspectFill;
        _bannerView.autoScrollTimeInterval = 5;
        _bannerView.backgroundColor = UIColorHex(0xf1f1f1);
        _bannerView.pageControlStyle = SDCycleScrollViewPageContolStyleAnimated;
//        _bannerView.placeholderImage = [UIImage imageNamed:@"placeholder_longrect"];
        _bannerView.delegate = self;
    }
    return _bannerView;
}

@end

